import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:acgn_pioneer/utils/_index.dart';
import 'package:acgn_pioneer/plugin/dialog/index.dart';
import '../public.dart';
import 'loading.dart';

/// 全局弹窗提示
class AcgnToast {
  dialog(BuildContext context,
      {String title,
      TextStyle titleStyle,
      Color backgroundColor,
      Clip clipBehavior,
      Widget content,
      List<Widget> actions,
      bool barrierDismissible = true,
      BoxConstraints constraints}) {
    if (actions == null) {
      actions = [
        FlatButton(
          color: Colors.transparent,
          // radius: BorderRadius.circular(0),
          child: Text(
            '取消',
            style: TextStyle(color: Colors.white, fontSize: 16),
          ),
          onPressed: () {
            Navigator.of(context).pop();
          },
        ),
        SizedBox(
          width: 1,
          height: 16,
          child: DecoratedBox(
            decoration: BoxDecoration(color: ColorUtil.rgba(18, 18, 26, 1)),
          ),
        ),
        FlatButton(
          color: Colors.transparent,
          child: Text(
            '确定',
            style: TextStyle(color: Colors.white, fontSize: 16),
          ),
          onPressed: () {
            Navigator.of(context).pop();
          },
        ),
      ];
    }
    Size size = MediaQuery.of(context).size;
    return ACGNDialog(context,
            clipBehavior: Clip.antiAlias,
            backgroundColor: backgroundColor ?? ColorUtil.rgba(40, 40, 56, 1),
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(8),
              side: BorderSide.none,
            ),
            barrier: DialogBarrier(
                barrierDismissible: barrierDismissible,
                barrierColor: ColorUtil.rgba(0, 0, 0, 0.35)),
            header: DialogHeader(
                title: title,
                alignment: Alignment.center,
                titleStyle: titleStyle ??
                    TextStyle(
                        fontSize: 16, color: ColorUtil.rgba(255, 255, 255))),
            body: DialogBody(
              content: content,
              padding: title != null
                  ? EdgeInsets.only(left: 20, right: 20, top: 10, bottom: 20)
                  : EdgeInsets.all(20),
              // decoration: BoxDecoration(
              //   color: Colors.greenAccent,
              // ),
              // scorllHeight: 200,
            ),
            footer: DialogFooter(
                hasClose: false,
                isVisible: true,
                actions: actions,
                decoration: BoxDecoration(
                    color: ColorUtil.rgba(45, 45, 61, 1),
                    border: Border(
                        top: BorderSide(
                            color: ColorUtil.rgba(18, 18, 26, 1),
                            width: 1,
                            style: BorderStyle.solid)))),
            transition: DialogTransition(type: AnimationType.fromBottom),
            constraints:
                constraints ?? BoxConstraints(maxWidth: size.width - 40))
        .show();
  }

  loading(
      {String status,
      Widget indicator,
      EasyLoadingMaskType maskType,
      bool dismissOnTap,
      Color maskColor}) {
    EasyLoading.instance
      ..loadingStyle = EasyLoadingStyle.custom
      ..backgroundColor = Colors.transparent
      ..indicatorColor = Colors.black87
      ..textColor = Colors.black87
      ..maskColor = maskColor ?? Colors.transparent;
    EasyLoading.show(
        status: status,
        indicator: indicator ??
            LoadingComponent(
              show: true,
              child: SizedBox.shrink(),
            ),
        maskType: maskType ?? EasyLoadingMaskType.custom,
        dismissOnTap: dismissOnTap);
  }

  message(msg,
      {Toast toastLength = Toast.LENGTH_SHORT,
      int timeInSecForIosWeb = 1,
      double fontSize = 16.0,
      ToastGravity gravity = ToastGravity.CENTER,
      Color backgroundColor,
      Color textColor,
      bool webShowClose = false,
      webBgColor: "linear-gradient(to right, #00b09b, #96c93d)",
      webPosition: "right"}) {
    Fluttertoast.showToast(
        msg: msg,
        toastLength: toastLength,
        timeInSecForIosWeb: timeInSecForIosWeb,
        fontSize: fontSize,
        gravity: gravity,
        backgroundColor: backgroundColor ?? ColorUtil.rgba(40, 40, 56, 1),
        textColor: textColor,
        webShowClose: webShowClose,
        webBgColor: webBgColor,
        webPosition: webPosition);
  }
}

final AcgnToast acgnToast = AcgnToast();
